<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<%@ page import="com.onlineMIS.common.Common_util"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script>

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	
	var params = $.serializeObject($('#preGenReportForm')); ;

	dataGrid = $('#dataGrid').datagrid({
		url : 'financeHQJSON!searchFinanceBillCorpFlow',
		queryParams: params,
		fit : true,
		border : false,
		pagination : true,
		pageSize : 15,
		pageList : [ 15, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		nowrap : false,	
		rowStyler: function(index,row){
			var style = "";
			if (row.status == STATUS_CANCEL)
				style += 'color:red;';
			else if (row.status == STATUS_DRAFT)
					style += 'color:blue;';
			return style;
		},
		rownumbers : true,
		sortName : 'createDate',
		sortOrder : 'desc',
		columns : [ [ 
			{
				field : 'id',
				title : '单据号',
				width : 50
			},{
				field : 'fromCategory',
				title : '转出机构',
				width : 80
			},{							    	
				field : 'toCategory',
				title : '转入机构',
				width : 80
			},{
				field : 'amount',
				title : '金额',
				width : 80
			}, {
				field : 'name',
				title : '转账人员',
				width : 80
			},{
				field : 'comment',
				title : '备注',
				width : 140
			}, {
				field : 'statusS',
				title : '状态',
				width : 50,
				sortable:true,
				order:'desc'
			}, {
				field : 'date',
				title : '单据日期',
				width : 100,
				sortable:true,
				order:'desc'
			}, {				
				field : 'createDate',
				title : '创建时间',
				width : 120,
				sortable:true,
				order:'desc'
			}, {
				field : 'lastUpdateDate',
				title : '最后一次修改时间',
				width : 120
			},  {			    
				field : 'edit',
				title : '编辑',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {
					
					var str = '';
					
					if (row.status == STATUS_DRAFT){
						var url = 'financeHQJSP!editFinanceBillCorpFlow?formBean.financeBillCorpFlow.id=' + row.id;
						str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="编辑账目"/></a>',url,'机构转账' + row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
						
					}
					    return str;
				}
			}, {			    
				field : 'delete',
				title : '删除',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {
					
					var str = '';
					
					if (row.status == STATUS_DRAFT){
						str += $.formatString('<a href="#" onclick="deleteFinanceCorpFlow(\'{0}\');"><img border="0" src="{1}" title="删除账目"/></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/delete.png');
						
					}
					    return str;
				}
			}, {			    
				field : 'cancel',
				title : '红冲',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {
					var str = '';
					
					if (row.status == STATUS_COMPLETE)
					    str += $.formatString('<a href="#" onclick="cancelFinanceCorpFlow(\'{0}\');"><img border="0" src="{1}" title="红冲账目"/></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/cancel3.png');
					return str;
				}
			}    
		     
		   ]],
			toolbar : '#toolbar',	
	});
});

function cancelFinanceCorpFlow(id){
	$.messager.confirm('确认','您确认想要红冲此条记录吗？',function(r){
	    if (r){	   
	        var params = "formBean.financeBillCorpFlow.id=" +id;
		    $.post("<%=request.getContextPath()%>/action/financeHQJSON!cancelFBillCorpFlow",params, confirmIsDelete,"json");	
	    }
	});
}




function deleteFinanceCorpFlow(id){
	$.messager.confirm('确认','您确认想要删除此条记录吗？',function(r){
	    if (r){	   
	        var params = "formBean.financeBillCorpFlow.id=" +id;
		    $.post("<%=request.getContextPath()%>/action/financeHQJSON!deleteFbillCorpFlow",params, confirmIsDelete,"json");	
	    }
	});
}

function confirmIsDelete(data){
	if(data != null){
		var returnCode = data.returnCode;
		if (returnCode === 3){
			 $.messager.alert('提示',data.message,'error');
		}else{			
			genSalesReport();
		}
		
	}
						
}

/**
 * 重置
 */
function resetSearch(){
	$("#status").combobox('setValue',<%=Common_util.ALL_RECORD%>);
	$("#institution").combobox('setValue',<%=Common_util.ALL_RECORD%>);
	$("#accounting").combobox('setValue',<%=Common_util.ALL_RECORD%>);
}

/**
 * 下载记录
 */
function dolwnloadRecord(){
	alert("下载记录暂未完成！")
}

function genSalesReport(){
	dataGrid.datagrid('load', $.serializeObject($('#preGenReportForm')));
}
</script>
</head>
<body>
	
	<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 95px;">
	<s:form id="preGenReportForm" name="preGenReportForm"		
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="40" colspan="7">
								<div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div>
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="35" colspan="9">机构转账记录:
										</td>
									</tr>
								<tr height="30" class="InnerTableContent">

								<td width="5%" align="center"><strong>单据日期:</strong></td>
								<td width="18%"><s:textfield id="startDate"
									name="formBean.searchStartTime" cssClass="easyui-datebox"
									data-options="width:100,editable:false" /> &nbsp;至&nbsp; <s:textfield
									id="endDate" name="formBean.searchEndTime" cssClass="easyui-datebox"
									data-options="width:100,editable:false" /></td>
								<td width="3%"><strong>状态:</strong></td>
								<td width="10%"><s:select id="status"  cssClass="easyui-combobox"
									name="formBean.financeBillCorpFlow.status" list="formBean.financeBillCorpFlow.statusMap"
									listKey="key" listValue="value" headerKey="-1"
									headerValue=""  data-options="prompt:'选择单据状态',width:120,editable:false"/></td>
								<td width="3%"><strong>机构：</strong></td>
								<td width="10%"><s:select id="institution"  cssClass="easyui-combobox"
									name="formBean.financeBillCorpFlow.fromAcctId.id" list="uiBean.financeCategory"
									listKey="id" listValue="itemName" headerKey="-1"
									headerValue=""  data-options="prompt:'选择机构信息',width:150,editable:false"/></td>
								<td width="3%"><strong>会计：</strong></td>
								<td width="10%"><s:select id="accounting"  cssClass="easyui-combobox"
									name="formBean.financeBillCorpFlow.userId.user_id" list="uiBean.userInfors"
									listKey="user_id" listValue="user_name" headerKey="-1" 
									headerValue=""  data-options="prompt:'选择会计',width:120,editable:false"/></td>	
								<td align="left">
													<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="resetSearch();" style="width: 60px">重置</a>
											</td>
						</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
			<div data-options="region:'center',border:false">
			<table id="dataGrid">
			</table>
			<div id="toolbar" style="display: none;">
				<a onclick="genSalesReport();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">查询转账</a>
					<a onclick="dolwnloadRecord();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-print',plain:true">下载记录</a>
			</div>
		</div>
</div>
	
</body>
</html>